home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / c_news / 17 / program8.pep < prev    next >
Text File  |  1989-08-23  |  3KB  |  8 lines

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define MAX_ROWS 99
  4. #define MAX_NAME 100
  5. #define HEAD1 "John Smith"
  6. #define HEAD2 "CIS 176, Section 02A"
  7. #define HEAD3 "Program 8"
  8. struct record{char name[30];int cover,code;};FILE*fptr;FILE*out;main(){struct record inputt;char names[MAX_ROWS][MAX_NAME];char coverage[MAX_ROWS][20];char plan[MAX_ROWS][20];float costs[MAX_ROWS][2];int count,cx;float empe_total,empr_total;float hp_costs[3][4]={{25.00,30.00,40.00,45.00},{30.00,40.00,55.00,60.00},{20.00,25.00,40.00,70.00}};count=0;empe_total=0;empr_total=0;if((fptr=fopen("indata","rb"))==NULL){printf("\nCannot open file for storing data.");exit(1);}while(fread(&inputt,sizeof(inputt),1,fptr)==1){printf("\nName:  %s",inputt.name);strcpy(names[count],inputt.name);printf("\nCoverage Code:  %d",inputt.cover);get_cover(inputt.cover,coverage,count);printf("\nHealth Plan Code:  %d\n",inputt.code);get_plan(inputt.code,plan,count);calc_costs(inputt.cover,inputt.code,costs,hp_costs);count++;}fclose(fptr);total_costs(costs,&empe_total,&empr_total,count);print_data(names,coverage,plan,costs,empe_total,empr_total,count,out);}get_cover(cover,array,count)int cover,count;char array[][20];{int counter=count;char typcvr[4][18]={{"Employee only"},{"Family coverage"},{"Reduced benefits"},{"** Error **"}};int temp;if(cover>2){temp=3;strcy(array[counter],typcvr[temp]);}else strcy(array[counter],typcvr[cover]);}get_plan(code,array,count)int code,count;char array[][20];{switch(code){case 0:strcy(array[count],"Standard");break;case 1:strcy(array[count],"HMO");break;case 2:strcy(array[count],"Premium");break;case 3:strcy(array[count],"ACME");break;default:strcy(array[count],"** Error **");break;}}calc_costs(cover,code,array3,array4)int cover,code;float array3[][2],array4[][4];{float tempcost[MAX_ROWS];int count;if(cover>2||code>3)tempcost[count]=0.00;else tempcost[count]=array4[cover][code];array3[count][1]=((tempcost[count])*(0.05));array3[count][2]=((tempcost[count])*(0.95));}total_costs(array,total1,total2,size)float array[][2],*total1,*total2;int size;{int counter;for(counter=0;counter<size;counter++)*total1+=array[counter][1];for(counter=0;counter<size;counter++)*total2+=array[counter][2];}print_data(array1,array2,array3,array4,total1,total2,size,out)char array1[][MAX_NAME+1],array2[][20],array3[][20];float array4[][2],total1,total2;int size;FILE*out;{int counter;out=fopen("d:output8","w");header(out);heading(out);for(counter=0;counter<size;counter++){printf("\n%s",array1[counter]);fprintf(out,"\n %-15s   %-19s   %-12s  $%6.2f     $%6.2f",array1[counter],array2[counter],array3[counter],array4[counter][1],array4[counter][2]);}fprintf(out,"\n%54c----------  ----------",' ');fprintf(out,"\n Totals:%46c$%7.2f    $%7.2f\n\n",' ',total1,total2);fclose(out);}heading(out)FILE*out;{fprintf(out,"\n%3cEmployee%30cHealth%9cEmployee%3cEmployer",' ',' ',' ',' ');fprintf(out,"\n%4cName%11cType of Coverage%7cPlan%12cCost%6cCost\n",' ',' ',' ',' ',' ');}strcy(copy,original)char*copy,*original;{while(*copy++=*original++);}header(out)FILE*out;{fprintf(out,"%30c%s\n",' ',HEAD1);fprintf(out,"%29c%s\n",' ',HEAD2);fprintf(out,"%34c%s\n",' ',HEAD3);}